package org.easy.tool.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.easy.tool.common.TimeUtil;
import org.easy.tool.entity.Type;
import org.easy.tool.entity.UserType;
import org.easy.tool.mapper.UserTypeMapper;
import org.easy.tool.service.IType;
import org.easy.tool.service.IUser;
import org.easy.tool.service.IUserType;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Valley
 * @since 2023-08-28 16:37:44
 */
@Service
public class UserTypeService extends ServiceImpl<UserTypeMapper, UserType> implements IUserType {

    @Autowired
    UserTypeMapper userTypeMapper;

    @Autowired
    IUser userService;
    @Autowired
    IType typeService;

    @Override
    public List<Type> getTypeListByUserId(String userId) {
        LambdaQueryWrapper<UserType> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserType::getUserId, userId);
        return userTypeMapper.selectList(wrapper).stream().map(UserType::getTypeId)
                .map(typeService::getTypeById).collect(Collectors.toList());
    }

    @Override
    public String addUserType(String userId, String typeId) {
        UserType userType = new UserType();
        userType.setTypeId(typeId);
        userType.setUserId(userId);
        userType.setCreateTime(TimeUtil.now());
        save(userType);
        return userType.getId();
    }

    @Override
    public UserType getUserTypeById(String userId, String typeId) {


        return null;
    }
}
